package co.yixiang.retail.common.utils;
import java.util.Random;

public class ConsumerCodeUtil {


    /**
     * 生成并返回随机的消费码 数字+字母
     * @param n
     * @return
     */
    public static String getItemID( int n )
    {
        String val = "";
        Random random = new Random();
        for ( int i = 0; i < n; i++ )
        {
            String str = random.nextInt( 2 ) % 2 == 0 ? "num" : "char";
            if ( "char".equalsIgnoreCase( str ) )
            { // 产生字母
                int nextInt = random.nextInt( 2 ) % 2 == 0 ? 65 : 97;
                // System.out.println(nextInt + "!!!!"); 1,0,1,1,1,0,0
                val += (char) ( nextInt + random.nextInt( 26 ) );
            }
            else if ( "num".equalsIgnoreCase( str ) )
            { // 产生数字
                val += String.valueOf( random.nextInt( 10 ) );
            }
        }
        return val;
    }

    /**
     * 生成并返回随机的消费码 纯数字
     * @param n
     * @return
     */
    public static String getItemIDRandom( int n){
        String val = "";
        Random random = new Random();
        n= n+random.nextInt(3);
        for ( int i = 0; i < n; i++ ) {
            val += String.valueOf(random.nextInt(10));
        }
        return val;

    }
}
